#ifndef __LIBAUTH_H
#define __LIBAUTH_H

#include "libpay.h"
#include <network.h>

#define	MAX_ADDR_SIZE		512
#define	MAX_AGENT_SIZE		80
#define MAX_REQ_SIZE		8192

#define MAX_KEYPATH_SIZE	512
#define MAX_CODEPHRASE_SIZE	80
#define MAX_KEYFILE_SIZE	80
#define MAX_KEYNUM_SIZE		25
#define MAX_CODE_SIZE		25


#define	CM_UNKNOWN		-1
#define CM_HTTP			0
#define CM_HTTPS		1


#define URL_SIZE	256
#define TMP_SIZE	4096

#define	WNOERROR		0
#define	WERR_INVALIDARGS	-1
#define WERR_CANTCREATESOCKET	-2
#define WERR_HOSTNOTFOUND	-3
#define	WERR_CANTCONNECT	-4


class CAuthServer
{
public:
// Proxy
	char m_szProxy[MAX_ADDR_SIZE];

// Common
	char m_szAgent[MAX_AGENT_SIZE];
	static int m_nCount;

// Checker
	char m_szKeyPath[MAX_KEYPATH_SIZE];
	char m_szCodePhrase[MAX_CODEPHRASE_SIZE];
	char m_szSecretKeyFile[MAX_KEYFILE_SIZE];
	char m_szPublicKeyFile[MAX_KEYFILE_SIZE];
	char m_szKeyNumber[MAX_KEYNUM_SIZE];
	char m_szBankKey[MAX_KEYNUM_SIZE];
	char m_szSD[MAX_CODE_SIZE];
	char m_szAP[MAX_CODE_SIZE];
	char m_szOP[MAX_CODE_SIZE];

public:
	CAuthServer();
	virtual ~CAuthServer(void);

	bool SetProxy(char* uri);
	bool SetAgentName(char*);
	bool SetKeyPath(char*);
	bool SetCodePhrase(char*);
	bool SetSecretKeyFile(char*);
	bool SetPublicKeyFile(char*);
	bool SetKeyNumber(char*);
	bool SetBankKey(char*);
	bool SetSD(char*);
	bool SetAP(char*);
	bool SetOP(char*);

	int SendRequest(char* uri,char* request,char* answer,int size);
	int SendRequestEx(char* uri,char* request,char* answer,int size);
	int PhoneCheck(char* uri,char* phone,char* amount,char* session,
		char* opname,char* account,char* errmsg=0);
	int SendPay(char* uri,char* phone,char* amount,char* session,char* account=0);
	int GetStatus(char* uri,char* session,int* state);
};

int strcopy(char* dst,char* src,int n);

#endif
